package com.appbee.media.client.presenter;

import javax.inject.Inject;

import com.appbee.core.client.place.EditPlace;
import com.appbee.core.client.place.HasPlace;
import com.appbee.core.client.place.IndexPlace;
import com.appbee.media.shared.MediaProxy;
import com.google.gwt.event.shared.EventBus;
import com.google.web.bindery.requestfactory.shared.Receiver;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;

public class MediaActivity extends AbstractMediaActivity
implements HasPlace
{
	public interface View extends IsWidget
	{
		void setActivity(MediaActivity activity);
		void showMedia(MediaProxy media);
	}
	
	private final View view;
	private EditPlace place;
	private final MediaDataProvider dataProvider;
	
	@Inject
	public MediaActivity(View view,MediaDataProvider dataProvider)
	{
		this.view = view;
		this.dataProvider = dataProvider;
		view.setActivity(this);
	}
	
	@Override
	public void start(final AcceptsOneWidget panel, EventBus eventBus)
	{
		Long id = place.getId();
		dataProvider.findById(id, new Receiver<MediaProxy>()
		{

			@Override
			public void onSuccess(MediaProxy result)
			{
				view.showMedia(result);
			}

		});
		panel.setWidget(view);
		
	}
	
	public void mediaViewClick(MediaProxy mediaProxy, int index)
	{
		placeController.goTo(new IndexPlace("mediathumbnail",(index/9)*9));
	}

	@Override
	public void setPlace(Place place)
	{
		this.place = (EditPlace) place;
	}

	public void doNext()
	{
	}

	public void doPrevius()
	{
	}

}
